package com.zrrd.learn.chapter04;

import java.util.Arrays;

/**
 * 数组
 *
 * @author asus
 * @version 1.0
 * @date 2023/5/20 13:26
 */
public class LearnArray {
    /**
     * 冒泡
     *
     */
    public static void bubble(int[]arr2){
        for (int j = 0; j < arr2.length-1; j++) {
            for (int i = 0; i < arr2.length-1-j; i++) {
                if (arr2[i]>arr2[i+1]){
                    arr2[i] = arr2[i]+arr2[i+1];
                    arr2[i+1]=arr2[i]-arr2[i+1];
                    arr2[i]=arr2[i]-arr2[i+1];
                }
            }
        }
    }
    public static void main(String[] args) {
//        [类型] [] [标识符] [=] [new] [类型][长度]
//        char[] c1=new char[3];
//
//        //使结果为[1, 3, 5, 7, 9, 11]
//        int[] int2={1,2,3,4,5,6};
//        System.out.println(Arrays.toString(int2));
//
//        for (int i = int2.length-1; i >0; i--) {
//            int2[i] = int2[i] +int2[i-1];
//        }
//        System.out.println(Arrays.toString(int2));

//        求最大值
        int[]arr2=new int[]{2,5,1};
        for (int j = 0; j < arr2.length-1; j++) {


        int max = Integer.MIN_VALUE;
        int index=0;
        for (int i = 0; i < arr2.length-j; i++) {
            if (max<arr2[i]){
                max=arr2[i];
                index=i;
            }
        }

       arr2[index]=arr2[arr2.length-1-j];
        arr2[arr2.length-1-j]=max;
        }
        System.out.println(Arrays.toString(arr2));

        //排序算法
        //交换位置
//        加法
        int c = 9 ;
        int b = 13;
        b=b+c;
        c=b-c;
        b=b-c;

//        减法
        b=b-c;
        c=b+c;
        b=c-b;
//        积法
        b=b*c;
        c=b/c;
        b=b/c;
//        ^ 异或

        System.out.println(c);
        System.out.println(b);

    }
}
